﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using Qianli.DirSir.Common;
using LTSMZ.life.Model;
using System.Data;

namespace LTSMZ.life.DAL
{
    public class SecondTypeDal
    {
        SQLHelper sqlhelper = new SQLHelper();
        /// <summary>
        /// 二级类别显示
        /// </summary>
        /// <returns></returns>
        public List<SecondType> SecondTypeShow(int Sid)
        {
            string sql = "SELECT SecondType.Fid,SecondType.Sid,SecondType.Sname,FirstType.Fname FROM SecondType JOIN FirstType ON FirstType.Fid=SecondType.Fid where SecondType.Fid=" + Sid + "";
            DataTable dt = sqlhelper.ExecDataTable(sql);
            List<SecondType> list = new List<SecondType>();
            foreach (DataRow d in dt.Rows)
            {
                SecondType f = new SecondType();
                f.Sid = Convert.ToInt32(d["Sid"]);
                f.Sname = d["Sname"].ToString();
                f.Fid = Convert.ToInt32(d["Fid"]);
                f.Fname = d["Fname"].ToString();
                list.Add(f);
            }
            return list;
        }
        /// <summary>
        /// 添加二级类别
        /// </summary>
        /// <param name="f"></param>
        /// <returns></returns>
        public int AddSecondType(SecondType f)
        {
            string sql = string.Format("insert into SecondType values('{0}',{1})", f.Sname, f.Fid);
            return sqlhelper.ExecNonquery(sql);
        }
        /// <summary>
        /// 删除二级类别
        /// </summary>
        /// <param name="Fid"></param>
        /// <returns></returns>
        public int DelSecondType(int Sid)
        {
            string sql = "delete from SecondType where Sid=" + Sid + "";
            return sqlhelper.ExecNonquery(sql);
        }
        /// <summary>
        /// 显示新鲜水果的类别
        /// </summary>
        /// <returns></returns>
        public List<SecondType> ShowSecond1()
        {
            string str = "select * from SecondType where Fid=1";
            DataTable dt = sqlhelper.ExecDataTable(str);
            List<SecondType> list = new List<SecondType>();
            foreach (DataRow d in dt.Rows)
            {
                SecondType s = new SecondType();
                s.Sname = d["Sname"].ToString();
                s.Sid = Convert.ToInt32(d["Sid"]);
                list.Add(s);
            }
            return list;
        }
    }
}
